﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClearSweet : MonoBehaviour {
    public AnimationClip animationClear;
    private bool isClearing;

    protected GameSweets gameSweet;
    public AudioClip clearClip;
    public bool IsClearing
    {
        get
        {
            return isClearing;
        }
        
    }


    public void Awake()
    {
        gameSweet = GetComponent<GameSweets>();
    }
    public virtual void Clear()
    {
        isClearing = true;
        StartCoroutine(ClearCoroutine());
    }

    private IEnumerator ClearCoroutine()
    {
        //获得当前的Animator组件并播放
        Animator animator = GetComponent<Animator>();
        if (animator != null)
        {
            animator.Play(animationClear.name);
            //分数增加 声音
            GameManager.Instance.Score++;
            AudioSource.PlayClipAtPoint(clearClip, transform.position);
            yield return new WaitForSeconds(animationClear.length);
            Destroy(this.gameObject);
        }
        
    }
}
